home *** CD-ROM | disk | FTP | other *** search
- // Dynamic link library implementation of a logistic function input source
-
- #include "NSDLL.h"
-
- typedef struct {
- NSFloat *data;
- int length;
- } ResultData;
-
- /***************************/
- /* Activation of component */
- __declspec(dllexport) void performInput(
- DLLData *instance, // Pointer to instance data (may be NULL)
- NSFloat *data, // Pointer to the data
- int rows, // Number of rows of data
- int cols // Number of cols of data
- )
- {
- int i;
- NSFloat constant = getFloatParameter(instance, 2, 1);
- ResultData *results = (ResultData*)getUserData(instance);
- for (i=0; i<results->length; i++)
- data[i] = results->data[i] = constant * results->data[i] * (1 - results->data[i]);
- }
-
- /**********************************************************************/
- /* Called before any performNoise calls, allowing any initialization. */
- __declspec(dllexport) void networkReset(
- DLLData *instance // Pointer to instance data (may be NULL)
- )
- {
- int i;
- NSFloat seed = getFloatParameter(instance, 3, 1);
- ResultData *results = (ResultData*)getUserData(instance);
- for (i=0; i<results->length; i++)
- results->data[i] = seed;
- }
-
- /******************************************/
- /* Management of instance data (OPTIONAL) */
- __declspec(dllexport) DLLData *allocInput(
- DLLData *oldInstance, // Pointer to the last instance if reallocating
- int rows, // Number of rows of data
- int cols // Number of cols of data
- )
- {
- DLLData *instance = allocDLLInstance(oldInstance);
- ResultData *results = calloc(1,sizeof(ResultData));
- results->length = rows*cols;
- results->data = calloc(results->length, sizeof(NSFloat));
- setUserData(instance, results);
- setParameterName(instance, 2, 1, "Constant", FALSE);
- setFloatParameter(instance, 2, 1, 4.0f, FALSE);
- setParameterName(instance, 3, 1, "Seed", FALSE);
- setFloatParameter(instance, 3, 1, 0.4f, FALSE);
- networkReset(instance);
- return instance;
- }
-
- __declspec(dllexport) void freeInput(DLLData *instance)
- {
- ResultData *results = (ResultData*)getUserData(instance);
- if (results) {
- free(results->data);
- free(results);
- }
- freeDLLInstance(instance);
- }
-